package com.humble.service;/*
  humble keep gonging
*/

import com.humble.bean.furn;
import com.humble.bean.furnExample;
import com.humble.dao.furnMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FurnService {
    @Resource
    private furnMapper mapper;

    public void save(furn furn){
        mapper.insertSelective(furn);
    }

    public List<furn> getAllFurns(){
        List<furn> furns = mapper.selectByExample(null);
        return furns;
    }

    public furn getFurnById(int id){
        furn furn = mapper.selectByPrimaryKey(id);
        return furn;
    }

    public void update(furn furn){
        mapper.updateByPrimaryKeySelective(furn);
    }

    public void delete(Integer id){
        mapper.deleteByPrimaryKey(id);
    }

    public List<furn> getFurnByName(String furnName){
        furnExample furnExample = new furnExample();
        furnExample.Criteria criteria = furnExample.createCriteria();
        if (StringUtils.hasText(furnName)) {
            criteria.andNameLike("%"+furnName+"%");
        }
        List<furn> furns = mapper.selectByExample(furnExample);
        return furns;
    }
}
